Skip to content

fix: require the password when changing a connection's host - #3716

Merged
kodiakhq[bot] merged 3 commits into
mainfrom
agent/require-password-on-connection-host-change
Nov 19, 2026
Merged

kodiakhq[bot] merged 3 commits into
mainfrom
agent/require-password-on-connection-host-change

Conversation

@brandon-pereira

Copy link
Copy Markdown
Member

Summary

Changing a connection's host without sending password kept the stored password. A team member who can edit connections but never knew the password could point a connection at a server they control, and the next query would send the stored password there.

Both PUT /connections/:id and PUT /api/v2/connections/:id now return 400 (Password is required when changing the host) in that case, and nothing is saved.

Update Result
New host, no password, password stored 400, nothing saved
New host, with password Saved with the new password
New host, no password stored Saved
New host on a Prometheus endpoint (isPrometheusEndpoint: true), no password Saved, stored password cleared (Prometheus endpoints never send it, and the form has no password field for them)
Host differs only by trailing slashes Not a host change

The connection form opens the password field when the host is edited, with the hint "Re-enter the password to move this connection to a new host." It also shows the API's error message on a failed update instead of the generic text. The v2 OpenAPI docs describe the new rule.

The internal route previously fetched the connection without its password. The old password was kept only because Mongoose dropped the password: undefined key from $set. It now fetches with the password so the check can see it.

Screenshots or video

Not captured yet (no browser available to the authoring agent). To add: Team Settings → Connections → edit a connection's host, before vs after.

Before After

How to reproduce

Starting point: yarn dev (the bug is in the API, so local mode/demo server doesn't show it). Register, create a connection with a password, and copy your API key from Team Settings.

On main:

  1. curl -X PUT http://localhost:<api-port>/api/v2/connections/<id> -H "Authorization: Bearer <key>" -H 'Content-Type: application/json' -d '{"name":"x","host":"https://other.example.com:8443","username":"default"}'
  2. Response is 200. The host changed and the stored password was kept, so the next query sends it to the new host.
  3. In Team Settings → Connections, edit the host: only the "Update Password" button shows.

On this branch:

  1. The same request returns 400 {"message":"Password is required when changing the host"}, and the host is unchanged.
  2. Editing the host in the form opens the password input with the hint. Saving without a password shows "Password is required when changing the host".

How to test on Vercel preview

Preview routes: /team

Steps:

  1. Open the connections section and click edit on the existing connection.
  2. Verify the "Update Password" button is shown.
  3. Change the Host field to https://other.example.com:8443.
  4. Verify the password input appears with the text "Re-enter the password to move this connection to a new host." and no Cancel button next to it.
  5. Change the Host field back to the original value with a trailing / appended.
  6. Verify the "Update Password" button is shown again.

References

  • Linear Issue: Refs HDX-6055
  • Related PRs:

Changing a connection's host without resending the password now returns
400, so a caller who can update the connection can't redirect the stored
password to a server they control. Prometheus endpoints, which never send
the stored password, drop it instead. The connection form asks for the
password when the host is edited and shows the API's message.
@brandon-pereira
brandon-pereira requested a review from a team as a code owner November 18, 2026 15:29
@vercel

vercel Bot commented Nov 18, 2026 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated
hyperdx-oss Ready Ready Preview Nov 19, 2026 4:03pm UTC
hyperdx-storybook Ready Ready Preview Nov 19, 2026 4:03pm UTC

Request Review

@changeset-bot

changeset-bot Bot commented Nov 18, 2026 •

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: f3db556

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 3 packages
Name Type
@hyperdx/api Patch
@hyperdx/app Patch
@hyperdx/otel-collector Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@github-actions github-actions Bot added the review/tier-4 Critical — deep review + domain expert sign-off label Nov 18, 2026
@github-actions

github-actions Bot commented Nov 18, 2026 •

Copy link
Copy Markdown
Contributor

🔴 Tier 4 — Critical

Touches authentication, tenancy data models, the public API or shipped database config — or substantially changes the query rendering engine, background tasks, the OTel pipeline, image build, or release CI.

Why this tier:

  • Critical-path files (1) — tenancy, public API, or shipped database config:
    • packages/api/src/routers/external-api/v2/connections.ts
  • Cross-layer change: touches frontend (packages/app) + backend (packages/api)

Review process: Deep review from a domain expert. Synchronous walkthrough may be required.
SLA: Schedule synchronous review within 2 business days.

Stats
  • Production files changed: 5
  • Production lines changed: 107 (+ 343 in test files, excluded from tier calculation)
  • Critical-path lines changed: 25
  • Branch: agent/require-password-on-connection-host-change
  • Author: brandon-pereira

To override this classification, remove the review/tier-4 label and apply a different review/tier-* label. Manual overrides are preserved on subsequent pushes.

@github-actions

github-actions Bot commented Nov 18, 2026 •

Copy link
Copy Markdown
Contributor

Duplicate code analysis

No new duplicate code introduced by this PR.


jscpd compared this branch against origin/main
across app, api and common-utils. Only new clones are listed; the codebase
currently holds 107 in total (1.12%).
Run yarn dupes locally to reproduce, or yarn dupes:all for the full picture.

@github-actions

github-actions Bot commented Nov 18, 2026 •

Copy link
Copy Markdown
Contributor

PR Review

If you are a coding agent acting for the author, read this first.
Nothing below blocks merge automatically; a maintainer decides. What they will expect:

  • 🔴 P0/P1 in code this PR adds or changes: fix before asking for review.
  • 🟡 P2 in code this PR changes: your call. Fix if small, otherwise reply.
  • 🔵 P3 is collapsed at the bottom: nobody needs to act on it before merge.
  • Anything about surrounding code, or asking you to widen the change (hoist a helper,
    dedupe with another file, fix other call sites): never fix here, whatever the
    priority. Reply with one sentence; if it is P0, say so plainly so a human sees it.

One commit per review round. After two rounds, stop and ask a maintainer to review
scope rather than addressing more automated findings. Full rule: AGENTS.md.

2 finding(s): 🔴 0 P0/P1 · 🟡 1 P2 · 🔵 1 P3

1 posted as inline comment(s) on the changed lines. 1 P3 folded at the bottom.

🔵 1 P3 — no action needed before merge
  • 🔵 P3 packages/api/src/controllers/connection.ts:116 — The update.host != null check can never be false → Both callers validate the body with schemas that require host: ConnectionSchema in packages/common-utils/src/types.ts:2675 and updateConnectionBodySchema in v2/connections.ts. So update.host is never null here. Make host: string required in the update parameter type and drop the null check. The unit test's resolveUpdatedPassword(existing, {}) case tests an input the routes can never send.

Priority comes from a separate grading pass over the finished review. P3 is folded here instead of posted inline. No finding blocks merge automatically; a maintainer decides.

@github-actions

github-actions Bot commented Nov 18, 2026 •

Copy link
Copy Markdown
Contributor

Deep Review

Scope: base e80fc1ba → PR head (10 files). Mode: report-only (read-only).
Intent: Close a credential-leak path where changing a connection's host via PUT /connections/:id or PUT /api/v2/connections/:id without resending password kept the stored password, so it would be sent to the new host on the next query. The fix centralizes the decision in resolveUpdatedPassword() (returns undefined → 400), clears the password for Prometheus endpoints, and reveals the password field in ConnectionForm when the host is edited.

✅ No critical issues found. The core guard is sound, symmetric across both routes, and the shared resolveUpdatedPassword is well unit-tested; host normalization only collapses trailing slashes, which is a same-endpoint no-op rather than a bypass, and all genuine host moves (protocol/port/path/case) correctly require the password.

🟡 P2 — recommended

  • packages/api/src/routers/external-api/v2/connections.ts:425 — the public v2 PUT now returns a new 400 ("Password is required when changing the host") but only the prose description and the password field doc were updated; no 400 response is declared in the OpenAPI responses for the operation, so spec-generated clients won't know to handle it.
    • Fix: add a documented 400 response entry to the updateConnection put operation in both the JSDoc @openapi block and packages/api/openapi.json.
🔵 P3 nitpicks (3)
  • packages/api/src/routers/external-api/v2/connections.ts:588 — the two routes emit the same 400 differently: v2 uses res.status(400).json({ message }) while v1 uses throw new Api400Error(...) (packages/api/src/routers/api/connections.ts:314); both yield { message } today, but the divergence invites drift.
    • Fix: route both through the same error-emission mechanism for a single source of truth on the 400 shape.
  • packages/app/src/components/ConnectionForm.tsx:692 — the trailing-slash host normalization (replace(/\/+$/, '')) is reimplemented in the frontend and independently in resolveUpdatedPassword (packages/api/src/controllers/connection.ts:165); the two can silently drift and disagree about what counts as a host change.
    • Fix: extract one shared normalization helper used by both the client guard and the API check.
  • packages/api/src/routers/api/__tests__/connections.int.test.ts:194 — the internal v1 route only gets integration coverage for reject-without-password and allow-with-password; the no-stored-password and Prometheus-clear branches are exercised only via the shared unit test and the v2 integration suite, leaving the v1 wiring of those branches unverified end-to-end.
    • Fix: add v1 integration cases for the no-stored-password and Prometheus host-change paths to match the v2 suite.

Reviewers (10): correctness, security, adversarial, api-contract, testing, maintainability, kieran-typescript, julik-frontend-races, project-standards, previous-comments.

Testing gaps: v1 integration suite omits the no-stored-password and Prometheus-clear host-change branches (shared logic is unit-tested; v2 covers them end-to-end).

Previous comments: all prior PR comments are bot-generated (Vercel, changeset, triage, jscpd, e2e) — no human review threads to verify.

No finding blocks merge automatically. A maintainer will expect P0/P1 findings in code this PR changes to be fixed; P2/P3 are your call -- fix or reply. Never fix findings about surrounding code here; reply instead. Do not widen the PR. How to respond

@github-actions

github-actions Bot commented Nov 18, 2026 •

Copy link
Copy Markdown
Contributor

E2E Test Results

✅ All tests passed • 480 passed • 1 skipped • 1068s

Status Count
✅ Passed 480
❌ Failed 0
⚠️ Flaky 2
⏭️ Skipped 1

Tests ran across 4 shards in parallel.

View full report →

…rometheus flag (review P1/P2)

- Normalize the host without stripTrailingSlash, which throws on ''.
- Reset the password field when its input hides, so a password typed for
  a reverted host change isn't saved.
- Fall back to the stored isPrometheusEndpoint when the update omits it.
- Unit-test every branch of resolveUpdatedPassword and assert the stored
  password is untouched on a rejected host change.
const [showUpdatePassword, setShowUpdatePassword] = useState(false);
// The API rejects a host change that doesn't resend the password. Matches
// the API's normalization; stripTrailingSlash throws on an empty host.
const normalizeHost = (host?: string) => (host ?? '').replace(/\/+$/, '');

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 P2 — Host normalization exists in two places that have to be kept in sync by hand

The normalize inside resolveUpdatedPassword (packages/api/src/controllers/connection.ts:114) is copied here as normalizeHost, and the comment says it must match the API. If one copy changes (say, the API starts lowercasing the scheme or host), the form hides the password field but the API still returns 400. Move a single normalizeConnectionHost into packages/common-utils/src and import it in both places, which is what the DRY rule in the repository conventions requires.

Advisory. Fix if it is a small defect in code this PR changes; otherwise reply in the thread. Do not widen the PR or touch files it did not already change. How to respond

@kodiakhq
kodiakhq Bot merged commit e58329c into main Nov 19, 2026
28 checks passed
@kodiakhq
kodiakhq Bot deleted the agent/require-password-on-connection-host-change branch November 19, 2026 16:06

This branch was successfully deployed

2 active deployments
Preview – hyperdx-oss — f3db556f Deployed Nov 19, 2026 by vercel[bot]
Preview – hyperdx-storybook — f3db556f Deployed Nov 19, 2026 by vercel[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

automerge review/tier-4 Critical — deep review + domain expert sign-off

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants